<?php
/**
 * Created by PhpStorm.
 * User: Marmot
 * Date: 2018/5/3
 * Time: 14:24
 */
namespace app\admin\controller;
use think\Controller;
use app\admin\model\User;
use think\captcha\Captcha;
class Login extends Controller{
    //显示登陆页
    public function index(){
        return $this->fetch();
    }
    //登陆方法
    public function login(){
        $username = $this->request->param('username');
        $password = $this->request->param('password');
        $verify = $this->request->param('verify');
        //验证验证码
        $captcha = new Captcha();
        if(!$captcha->check($verify)){
//            //验证失败
            echo 444;die;
        }
        //用户名密码验证

        $user = new User();
        $users = $user->get([
            'user_name' => $username,
            'pass_word' => md5(md5($password)),
        ]);

        if ($users){
            session('login',$users);
            //成功登陆
            echo 666;
        }else{
            //用户名与密码不匹配
            echo 222;
        }
    }
    //登陆验证码
    public function verify(){
        $captcha = new Captcha();
        return $captcha -> entry();
    }
    //退出登陆
    public function loadOut(){
        session('login',null);
        $this->redirect('login/index');
    }
}
